/**
 * Created by Administrator on 2018/1/15.
 */
define(function(require, exports, module) {
    var $=require('zepto');
    cn=require('conment');
    drop=require('dropload');
    api=require('api')
    module.exports = {
        int:{
            sellId:cn.getQueryString('id'),
        },
        getNowFormatDate:function () {
            var date = new Date();
            var seperator1 = "-";
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            var currentdate = year + seperator1 + month + seperator1 + strDate;
            return currentdate;
        },
        dealDetail:function (me) {
            const _this=this;
            cn.Ajax(api.dealDetail,{
               id:cn.getQueryString('id'),
            },function(c){
                // console.log(c)
                if(c.flag==1){
                    var data=c.data;
                    $('#dadang').text(data.investorDisplayName);
                    $('#gudong').text(data.investorHolderCode);
                    $('#typeStr').text(data.typeStr);
                    $('#name').text(data.name);
                    $('#num').text(data.buyQuantity+'股');
                    $('#code').text(data.code);
                    $('#amount').text(data.amount);
                    $('#profitPercent').text(parseFloat(data.profitPercent)*100+"%");
                    $('#amountRate').text(data.amountRate);


                    $('#buyTime1').text(data.buyMarkTimeStr==null?"--":data.buyMarkTimeStr);
                    $('#buyTime2').text(data.buyTimeStr==null?"--":data.buyTimeStr);
                    $('#buyPrice').text((data.buyPrice==0?"--":data.buyPrice)+'元');
                    $('#buyMoney').text((data.buyAmount==0?"--":data.buyAmount)+'元');

                    $('#sellTime1').text(data.sellMarkTimeStr==null?'--':data.sellMarkTimeStr);
                    $('#sellTime2').text(data.sellTimeStr==null?'--':data.sellTimeStr);
                    $('#sellPrice').text((data.sellPrice==0?"--":parseFloat(data.sellPrice).toFixed(2))+'元');
                    $('#sellMoney').text((data.sellAmount==0?"--":data.sellAmount)+'元');
                    if(data.state>=8){
                        $('#dealYk').text(parseFloat(data.sellAmount)-parseFloat(data.buyAmount)+'元').addClass(parseFloat(data.amountDifference)>0?'red':'green');
                        $('#dealFp').text(data.amountDifference+'元').addClass(parseFloat(data.amountDifference)>0?'red':'green');
                    }
                    // console.log((_this.getNowFormatDate()!=(data.buyTimeStr).substring(0,10)))
                    if((data.state==4)&&(_this.getNowFormatDate()!=(data.buyTimeStr).substring(0,10))){
                        $('.detailBtn').show();
                        $('#sellDetail').removeAttr("disabled")
                    }

                }
            },'post');

        },
        sellDeal:function () {
            const _this=this;
            cn.loadHtml({
                txt:'寻找搭档',
                time:15,
                is:true,
            });
            cn.Ajax(api.sell,{
                id : _this.int.sellId,
            },function(d){
                cn.loadHtml({
                    is:false,
                });
                if(d.flag==1){
                    cn.alert(d.message);
                }else{
                    cn.alert(d.message);
                }

            },'post')
        },
        init:function () {
            const _this=this;
            _this.dealDetail();
            $('#sellDetail').on('click',function () {
                cn.modelDialog({
                    msg:'确定卖出此策略？',
                    btnValue:'取消',
                    btn:[{
                        txt:'确定',
                        callBack:function(){
                            _this.sellDeal();
                        }
                    }]
                });

            })
        }
    }

});

